﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Qkds.Erp.WebUi
{
    public partial class shoplist : System.Web.UI.Page
    {
        public int pid
        {
            get
            {
                return int.Parse(ViewState["pid"].ToString());
            }
            set
            {
                ViewState["pid"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pid = 0;
                if (Request["id"] != null)
                {
                    string TableName = "shop";
                    pid = int.Parse(Request["id"].ToString());
                    ShopModel model = new ShopBLL().GetModelByID(TableName,pid);
                    
                    this.txtName.Value = model.Name;
                    this.txtPrice.Value = model.Price.ToString();
                    this.txtPricen.Value = model.nPrice.ToString();
                    this.txtNum.Value = model.Num.ToString();
                }

            }
        }
        protected void btnSave_click(object sender, EventArgs e)
        {
            ShopModel model = new ShopModel()
            {
                Name = this.txtName.Value,
                Price = decimal.Parse(this.txtPrice.Value),
                nPrice = decimal.Parse(this.txtPricen.Value),
                Num = int.Parse(this.txtNum.Value)
            };
            ShopBLL bll = new ShopBLL();
            if (pid > 0)
            {
                bll.Gai(model,pid);

            }
            else
            {
                bll.Add(model);


            }
            Response.Redirect("Shopinfo.aspx");
        }
    }
}